<template>
  <div class="body">
    <!-- <el-button type="primary" icon="el-icon-upload2">导出</el-button> -->
    <!-- <el-button type="danger" @click="del()" icon="el-icon-delete">删除</el-button> -->
    <el-tabs v-model="activeName" @tab-click="handleClick">
      <el-tab-pane label="待审核" name="first">
        <el-row style="margin-top: 10px" class="mb8">
          <el-col :span="19">
            <el-button
              type="info"
              @click="shuaxin"
              icon="el-icon-refresh-right"
            ></el-button>
            <!-- <el-button type="success" @click="handleAdd" icon="el-icon-plus">上传</el-button> -->
          </el-col>
          <el-col :span="5" class="seach">
            <el-input
              v-model="params.keywords"
              placeholder="请输入文件名称"
            ></el-input>
            <el-button
              type="primary"
              icon="el-icon-search"
              @click="shuaxin"
            ></el-button>
          </el-col>
        </el-row>
        <!-- <el-button @click="$router.go(0)" type="info" icon="el-icon-refresh-right"></el-button> -->
        <el-table
          ref="multipleTable"
          :data="tableData"
          tooltip-effect="dark"
          class="table xindes"
          @selection-change="handleSelectionChange"
        >
          <el-table-column type="selection" width="55"></el-table-column>
          <el-table-column prop="id" label="序号" width="120"></el-table-column>
          <el-table-column
            prop="cardname"
            width="120"
            label="经办人姓名"
          ></el-table-column>
          <el-table-column
            prop="mobile"
            width="220"
            label="经办人联系方式"
          ></el-table-column>
          <el-table-column
            prop="cardcode"
            width="220"
            label="经办人身份证号"
          ></el-table-column>
          <el-table-column width="220" label="身份证正面">
            <template slot-scope="scope">
              <!-- {{scope.row.}} -->
              <el-image
                style="width: 60px"
                :src="$baseUrl + scope.row.cardfront"
              ></el-image>
              <!-- <img :src="$baseUrl + scope.row.cardfront" alt=""> -->
            </template>
          </el-table-column>
          <el-table-column width="220" label="身份证反面">
            <template slot-scope="scope">
              <!-- {{scope.rows.cardback}} -->
              <el-image
                style="width: 60px"
                :src="$baseUrl + scope.row.cardback"
              ></el-image>
              <!-- <img :src="$baseUrl + scope.row.cardback" alt=""> -->
            </template>
          </el-table-column>
          <el-table-column prop="createtime" width="220" label="申请时间">
            <template slot-scope="scope">{{
              scope.row.createtime | dateFormat
            }}</template>
          </el-table-column>
          <el-table-column
            prop="cardcode"
            width="220"
            label="申请原因"
          ></el-table-column>
          <el-table-column
            label="操作"
            align="center"
            class-name="small-padding fixed-width"
          >
            <template slot-scope="scope">
              <el-button type="text" icon @click="tongguo(scope.row)"
                >审核
              </el-button>
            </template>
          </el-table-column>
        </el-table>
        <div class="block">
          <el-pagination
            background
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
            :page-sizes="[10, 20, 30]"
            :page-size="params.pageSize"
            :current-page.sync="params.pageNum"
            layout="total, sizes, prev, pager, next, jumper"
            :total="total"
          ></el-pagination>
        </div>
      </el-tab-pane>
      <el-tab-pane label="已拒绝" name="second">
        <el-row style="margin-top: 10px" class="mb8">
          <el-col :span="19">
            <el-button
              type="info"
              @click="shuaxin"
              icon="el-icon-refresh-right"
            ></el-button>
            <!-- <el-button type="success" @click="handleAdd" icon="el-icon-plus">上传</el-button> -->
          </el-col>
          <el-col :span="5" class="seach">
            <el-input
              v-model="params.keywords"
              placeholder="请输入文件名称"
            ></el-input>
            <el-button
              type="primary"
              icon="el-icon-search"
              @click="shuaxin"
            ></el-button>
          </el-col>
        </el-row>
        <el-table
          ref="multipleTable"
          :data="tableData"
          tooltip-effect="dark"
          class="table xindes"
          @selection-change="handleSelectionChange"
        >
          <el-table-column type="selection" width="55"></el-table-column>
          <el-table-column prop="id" label="序号" width="120"></el-table-column>
          <el-table-column prop="cardname" label="经办人姓名"></el-table-column>
          <el-table-column
            prop="mobile"
            label="经办人联系方式"
          ></el-table-column>
          <el-table-column
            prop="cardcode"
            label="经办人身份证号"
          ></el-table-column>
          <el-table-column label="身份证正面">
            <template slot-scope="scope">
              <el-image
                style="width: 60px"
                :src="$baseUrl + scope.row.cardfront"
              ></el-image>
              <!-- <img :src="$baseUrl + scope.row.cardfront" alt=""> -->
            </template>
          </el-table-column>
          <el-table-column label="身份证反面">
            <template slot-scope="scope">
              <el-image
                style="width: 60px"
                :src="$baseUrl + scope.row.cardback"
              ></el-image>
              <!-- <img :src="$baseUrl + scope.row.cardback" alt=""> -->
            </template>
          </el-table-column>
          <!-- <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
            <template slot-scope="scope">
              <el-button type="text" icon @click="again(scope.row)">再次申请
              </el-button>
            </template>
          </el-table-column> -->
        </el-table>
        <div class="block">
          <el-pagination
            background
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
            :page-sizes="[10, 20, 30]"
            :page-size="params.pageSize"
            :current-page.sync="params.pageNum"
            layout="total, sizes, prev, pager, next, jumper"
            :total="total"
          ></el-pagination>
        </div>
      </el-tab-pane>
      <el-tab-pane label="已通过" name="third">
        <el-row style="margin-top: 10px" class="mb8">
          <el-col :span="19">
            <el-button
              type="info"
              @click="shuaxin"
              icon="el-icon-refresh-right"
            ></el-button>
            <!-- <el-button type="success" @click="handleAdd" icon="el-icon-plus">上传</el-button> -->
          </el-col>
          <el-col :span="5" class="seach">
            <el-input
              v-model="params.keywords"
              placeholder="请输入文件名称"
            ></el-input>
            <el-button
              type="primary"
              icon="el-icon-search"
              @click="shuaxin"
            ></el-button>
          </el-col>
        </el-row>
        <el-table
          ref="multipleTable"
          :data="tableData"
          tooltip-effect="dark"
          class="table xindes"
          @selection-change="handleSelectionChange"
        >
          <el-table-column type="selection" width="55"></el-table-column>
          <el-table-column prop="id" label="序号" width="120"></el-table-column>
          <el-table-column prop="cardname" label="经办人姓名"></el-table-column>
          <el-table-column
            prop="mobile"
            label="经办人联系方式"
          ></el-table-column>
          <el-table-column
            prop="cardcode"
            label="经办人身份证号"
          ></el-table-column>
          <el-table-column label="身份证正面">
            <template slot-scope="scope">
              <el-image
                style="width: 60px"
                :src="$baseUrl + scope.row.cardfront"
              ></el-image>
              <!-- <img :src="$baseUrl + scope.row.cardfront" alt=""> -->
            </template>
          </el-table-column>
          <el-table-column label="身份证反面">
            <template slot-scope="scope">
              <el-image
                style="width: 60px"
                :src="$baseUrl + scope.row.cardback"
              ></el-image>
              <!-- <img :src="$baseUrl + scope.row.cardback" alt=""> -->
            </template>
          </el-table-column>
          <!-- <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
            <template slot-scope="scope">
              <el-button type="text" icon @click="cancel(scope.row)">取消代理
              </el-button>
            </template>
          </el-table-column> -->
        </el-table>
        <div class="block">
          <el-pagination
            background
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
            :page-sizes="[10, 20, 30]"
            :page-size="params.pageSize"
            :current-page.sync="params.pageNum"
            layout="total, sizes, prev, pager, next, jumper"
            :total="total"
          ></el-pagination>
        </div>
      </el-tab-pane>
    </el-tabs>

    <!-- 审核弹窗 -->
    <el-dialog title="" :visible.sync="dialogVisible" width="40%">
      <el-form
        :model="ruleForms"
        :rules="rules"
        ref="ruleForm"
        label-width="120px"
      >
        <el-form-item label="经办人姓名 :">
          <el-input v-model="ruleForms.cardname"></el-input>
        </el-form-item>
        <el-form-item label="经办人联系方式 :">
          <el-input v-model="ruleForms.mobile"></el-input>
        </el-form-item>
        <el-form-item label="经办人身份证号 :">
          <el-input v-model="ruleForms.cardcode"></el-input>
        </el-form-item>
        <el-form-item label="经办人身份证 :">
          <div class="avatar">
            <img :src="$baseUrl + ruleForms.cardfront" />
          </div>
          <div class="line"></div>
          <div class="avatar">
            <img :src="$baseUrl + ruleForms.cardback" />
          </div>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="" @click="shenhe">通过</el-button>
        <el-button @click="reasonClick">拒绝</el-button>
      </div>
    </el-dialog>
    <el-dialog title="" :visible.sync="refuseShow" width="30%">
      <div style="font-size: 16px">
        <span>拒绝原因：</span>
        <el-input
          type="textarea"
          :rows="2"
          placeholder="请输入内容"
          v-model="reason"
          style="margin: 10px 0"
        >
        </el-input>
      </div>
      <div slot="footer" class="dialog-footer">
        <el-button type="" @click="shenhes">提交</el-button>
        <el-button @click="refuseShow == false" class="">取消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { daili, dailidel, shenhedaili } from "@/api/handledby";
export default {
  data() {
    return {
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 表单参数
      form: {
        name: "",
      },
      // 表单校验
      rules: {},
      params: {
        pageSize: 10,
        pageNum: 0,
        // daili: 1,
        keywords: "",
      },
      total: null,
      tableData: [],
      multipleSelection: [],
      activeName: "first",
      dialogVisible: false, //审核弹窗
      refuseShow: false, //拒绝弹窗
      ruleForm: {},
      reason: "", //拒绝原因
      ruleForms: "",
    };
  },
  created() {
    this.gethandledby();
  },
  methods: {
    handleClick(e) {
      // console.log(Number(e.index))
      this.params.daili = Number(e.index) + 1;
      this.gethandledby();
    },
    shuaxin() {
      this.gethandledby();
    },
    tongguo(e) {
      console.log("yulan", e);
      this.dialogVisible = true;
      this.ruleForms = e;
    },
    // 拒绝
    reasonClick() {
      this.refuseShow = true;
    },
    // 再次申请
    again() {
      this.$confirm("你确定再次提交申请吗?", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          this.$message({
            type: "success",
            message: "申请成功!",
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消申请",
          });
        });
    },
    // 取消代理
    cancel() {
      this.$confirm("你确定取消代理吗?", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          this.$message({
            type: "success",
            message: "取消代理成功!",
          });
        })
        .catch(() => {});
    },
    shenhe() {
      var cion = {
        id: this.ruleForms.id,
        daili: 3,
      };
      shenhedaili(cion).then((res) => {
        if (res.data.code == 1) {
          console.log("申请代理", res);
          this.$message({
            showClose: true,
            message: res.data.msg,
            type: "success",
          });
          this.gethandledby();
          this.dialogVisible = false;
        } else {
          this.$message({
            showClose: true,
            message: res.data.msg,
            type: "error",
          });
        }
      });
    },
    shenhes() {
      var cion = {
        id: this.ruleForms.id,
        daili: 2,
      };
      shenhedaili(cion).then((res) => {
        if (res.data.code == 1) {
          console.log("申请代理", res);
          this.$message({
            showClose: true,
            message: res.data.msg,
            type: "success",
          });
          this.dialogVisible = false;
          this.refuseShow = false;
          this.gethandledby();
        } else {
          this.$message({
            showClose: true,
            message: res.data.msg,
            type: "error",
          });
        }
      });
    },
    // 获取经办人列表
    gethandledby() {
      // this.params.user_id = sessionStorage.getItem("user_id");
      daili(this.params).then((res) => {
        if (res.data.code == 200) {
          this.tableData = res.data.rows;
          this.total = res.data.total;
        }
      });
    },
    // 表单重置
    reset() {
      this.form = {};
    },
    del() {
      let arr = [];
      this.multipleSelection.forEach((item) => {
        arr.push(item.id);
      });
      arr = arr.toString();
      console.log(arr);
      // let user_id = sessionStorage.getItem("user_id");
      dailidel({ ids: arr }).then((res) => {
        if (res.data.code == 1) {
          this.$message.success("删除成功");
          this.gethandledby();
        } else {
          this.$message.error("网络异常,稍后再试");
        }
      });
    },
    // 单选框选中时
    handleSelectionChange(val) {
      this.multipleSelection = val;
    },
    // 表格显示个数
    handleSizeChange(val) {
      this.params.pageSize = val;
      this.gethandledby();
    },
    // 页码
    handleCurrentChange(val) {
      this.params.pageNum = val;
      this.gethandledby();
    },
  },
};
</script>

<style scoped lang="scss">
.body {
  width: 100%;
  // height: 100%;
}

.table {
  width: 100%;
  margin-top: 0vh;
  // flex:1;
}

.block {
  height: 50px;
  display: flex;
  justify-content: end;
  padding-top: 10px;
  padding-right: 10px;
}

.dialog-footer {
  width: 100%;
  display: flex;
  justify-content: center;
  align-items: center;

  .el-button {
    width: 120px;
  }
}

::v-deep .el-dialog .el-dialog__header {
  // background-color: #005de8 !important;
  padding: 10px 20px;
  box-sizing: border-box;
  height: 45px;

  .el-dialog__title,
  .el-dialog__headerbtn .el-dialog__close {
    color: #333 !important;
    font-size: 20px !important;
  }

  .el-dialog__headerbtn {
    top: 12px;
  }
}

::v-deep .el-dialog .el-dialog__body {
  padding: 0 20px;
}

::v-deep .el-form-item {
  margin-bottom: 10px;
  display: flex;

  .el-form-item__content {
    width: 100%;
    margin-left: 0 !important;
  }
}

.avatar {
  width: 100%;
  height: 170px;

  img {
    width: 100%;
    height: 100%;
  }
}

.line {
  width: 100%;
  height: 3px;
  background-color: rgb(214, 195, 195);
}

.el-tabs {
  width: 100%;
  height: 100%;
}

::v-deep .el-tabs__header {
  margin: 0 !important;
}
::v-deep .el-tabs__content {
  width: 100%;
  // height: 100%;
  .el-tab-pane {
    // height: 100%;
    // display: flex;
    // flex-direction: column;
  }
}
</style>
